﻿using System.Collections.Generic;
using System.Web;
using System.Collections.Specialized;

namespace Microsoft.IdentityModel.OAuth
{
    public static class Extensions
    {
        public static TValue GetAndRemove<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key)
        {
            TValue value = default(TValue);
            if (source.TryGetValue(key, out value))
                source.Remove(key);
            return value;
        }

        public static string UrlEncode(this string source)
        {
            return HttpUtility.UrlEncode(source);
        }

        public static string UrlDecode(this string source)
        {
            return HttpUtility.UrlDecode(source);
        }
        public static bool Contains(this NameObjectCollectionBase.KeysCollection source, string key)
        {
            foreach (var k in source)
            {
                if (k.ToString() == key)
                    return true;
            }
            return false;
            
        }
    }
}
